<%--
  Created by IntelliJ IDEA.
  User: zyh
  Date: 2021/11/18
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <form action="${ctx}/emp/login" method="post" id="loginForm">
                <div class="form-group">
                    <label for="exampleInputEmail1">用户名</label>
                    <input type="text" class="form-control" name="ename" id="exampleInputEmail1" placeholder="Email">
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码</label>
                    <input type="password" class="form-control" name="pwd" id="exampleInputPassword1" placeholder="Password">
                </div>
                <img src="${ctx}/captcha" style="width:85px" id="cap"/>
                <div class="form-group">
                    <label for="exampleInputEmail6">输入验证码</label>
                    <input type="text" class="form-control" id="code" name="code" id="exampleInputEmail6" placeholder="Email">
                </div>
                <button type="button" class="btn btn-default" id="sub">Submit</button><span id="msg"></span>
            </form>
        </div>
    </div>
</div>
<script>
    $(function () {
            $("#sub").click(function () {
                let data = $("#loginForm").serialize();
                $.ajax({
                    url:"${ctx}/emp/login",
                    data:data,
                    success:function (result) {
                        if (result=="0") {
                            location.href="${ctx}/emp/index";
                        }else {
                            $("#msg").text("账号密码错误");
                        }
                    }
                })
            });


            $(function(){
                $("#cap").click(function(){
                    //刷新验证码
                    path = $(this).attr("src")+"?"+new Date().getTime();
                    $(this).attr("src",path);
                });
            });
    })
</script>
</body>
</html>
